package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.entity.banquet.BanquetInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.banquet.CrossBanquetAutoMgr;
import com.yanqu.road.server.manager.banquet.CrossBanquetConfigMgr;
import com.yanqu.road.server.manager.banquet.CrossBanquetMgr;
import com.yanqu.road.server.manager.banquet.CrossPartyMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_UPDATE_PARTY_SETTING, desc = "更新进行中的宴会的设置,可接受礼物类型")
public class CrossUpdatePartySettingCmd extends CrossCommand {
    private long userId;
    private int type;
    private String giftTypeAccept;
    private String banquetId;

    private String message;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BanquetProto.UpdateBanquetSettingReqMsg req = BanquetProto.UpdateBanquetSettingReqMsg.parseFrom(packet.getBytes());
        this.userId = packet.getPlayerId();
        this.type = req.getType();
        this.giftTypeAccept = req.getGiftTypeAccept();
        this.banquetId = req.getBanquetId();
        this.message = req.getMessage();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BanquetInfo banquetInfo = CrossBanquetMgr.getBanquetInfo(banquetId);
        if(banquetInfo != null && CrossBanquetConfigMgr.isCrossUserBanquet(banquetInfo.getId())){
            List<Integer> giftIdList = StringUtils.stringToIntegerList(giftTypeAccept,"\\|");
            if(!CrossBanquetAutoMgr.canSetGiftIdList(userId,banquetInfo,giftIdList)){
                return;
            }
        }
        if (!CrossPartyMgr.updatePartySetting(serverId, userId, type, giftTypeAccept, banquetId, message)) {
            CrossBanquetMgr.updatePartySetting(serverId, userId, type, giftTypeAccept, banquetId, message);
        }
    }

    @Override
    public void sendData() {

    }
}
